import app from "../main";
import store from "../store";
import routes from './AsyncRoutes'
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
});

// eslint-disable-next-line no-unused-vars
router.beforeEach((to, from, next) => {
    if (to.meta) {
        // 路由变化时更改标题
        document.title = app.$t('sidebar.' + to.meta.name) === 'sidebar.' + to.meta.name ? to.meta.name : app.$t('sidebar.' + to.meta.name);
        if (to.meta.target) {
            next();
            return
        }
        if (to.meta.showIframe) {
            store.state.showIframe = true;
            store.state.iframeUrl = to.meta.iframeUrl;
        } else {
            store.state.showIframe = false;
            store.state.iframeUrl = null;
        }
    }
    next()
});

export default router
